<?php
class ModelMessageCardManage extends Model {
	public function getAllCardManage(){
		
		$sql = "select * from ".DB_PREFIX."config_card_manage";
		$cardManages = $this->db->query($sql)->rows;
		$result = array();
		if($cardManages){
			foreach ($cardManages as $cardManage) {
				$result[]=array(
					'police_office' =>$cardManage['police_office'],
					'address' =>$cardManage['address'],
					'dianhua' =>$cardManage['dianhua'],
					'police_station' =>$cardManage['police_station'],
					'so' =>$cardManage['so'],
					'police' =>$this->getPolice($cardManage['card_manage_id']),
					'assistant_police' =>$this->getAssistantPolice($cardManage['card_manage_id']),
				);
			}
		}
		return $result;
	}
	
	public function getPolice($card_manage_id){
		$sql = "select * from ".DB_PREFIX."config_police_to_card_manage cpccm left join ".DB_PREFIX."config_police cp on(cp.police_id=cpccm.police_id) where cpccm.card_manage_id='".(int)$card_manage_id."'";
		return $this->db->query($sql)->row;
	}
	
	public function getAssistantPolice($card_manage_id){
		$sql = "select * from ".DB_PREFIX."config_assistant_police_to_card_manage cpccm left join ".DB_PREFIX."config_assistant_police cp on(cp.assistant_police_id=cpccm.assistant_police_id) where cpccm.card_manage_id='".(int)$card_manage_id."'";
		return $this->db->query($sql)->row;
	}
	
	
}
?>